import { createElement } from './vdom/vnode.js'
import { initProps, initMethods, initData, initComputed, initWatch } from './data/index.js'
import observe from '../core/observe.js'
import defineReactive from '../core/defineReactive.js'
export function mergeOptions(parent, child, vm) {
    // 未来再写
    return parent
}
export const resolveConstructorOptions = option => option

export function initLifecycle(vm) {
    // 未来再写
    const options = vm.$options
    let parent = options.parent
    vm.$parent = parent
    vm.$root = parent ? parent.$root : vm
    vm.$children = []
    vm.$refs = {}
    vm._watcher = null
    vm._inactive = null
    vm._directInactive = false
    vm._isMounted = false
    vm._isDestroyed = false
    vm._isBeingDestroyed = false
}
export function initEvents(vm) {
    // 未来再写
    vm._events = Object.create(null)
    vm._hasHookEvent = false
}
export function initRender(vm) {
    // 未来再写
    vm._vnode = null // the root of the child tree
    vm._staticTrees = null // v-once cached trees
    const options = vm.$options
    const parentVnode = vm.$vnode = options._parentVnode // the placeholder node in parent tree
    const renderContext = parentVnode && parentVnode.context
    vm._c = (a, b, c, d) => createElement(vm, a, b, c, d, false)
    vm.$createElement = (a, b, c, d) => createElement(vm, a, b, c, d, true)

}
export function callHook(vm, hook) {
    // 未来补全
    const handlers = vm.$options[hook] // 拿到方法
    const info = `${hook} hook`
    if (handlers) { // 判断
        for (let i = 0, j = handlers.length; i < j; i++) {
            // 检查错误
            // invokeWithErrorHandling(handlers[i], vm, null, vm, info)
        }
    }
    console.log(hook)
    if (vm._hasHookEvent) { // 判断？？？？？？？
        vm.$emit('hook:' + hook)
    }
}
export const initInjections = vm => vm;
export function initState(vm) {
    vm._watchers = []
    const opts = vm.$options
    if (opts.props) initProps(vm, opts.props)
    if (opts.methods) initMethods(vm, opts.methods)
    if (opts.data) {
        initData(vm)
    } else {
        observe(vm._data = {}, true /* asRootData */ )
    }
    if (opts.computed) initComputed(vm, opts.computed)
    if (opts.watch) {
        initWatch(vm, opts.watch)
    }
}
export const initProvide = vm => vm;